 function GridSelect(sname,ahashead) {	 
	this.Main_Tab = $(sname); 
	this.Main_TabDom =this.Main_Tab.get(0); 
	this.ClickRow; 
	var Me = this; 
	var hashead =false ; 
	if(ahashead !=null && ahashead !=undefined)
	{
		hashead = ahashead;
	}else
	{
		if (this.Main_Tab.find("thead"))
	    {
		   hashead =true;
	    }
	} 
    
	function get_Element (the_ele,the_tag){ 
	   if(the_ele==null || the_ele==undefined){
	     return(null);
	   } 
		if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
		while(the_ele = the_ele.parentElement ){
			if(the_ele.tagName.toLowerCase()==the_tag)
			   return the_ele;
			else if (the_ele.tagName.toLowerCase() =="table"){
			   return(null);
			}
		}
		return(null);
	};
	 
	this.getrowvalue =function()
	 {   
	 	if( this.ClickRow ==null  ||  this.Main_TabDom.rows.length <= 1 ) 
	 	{  
	 		return null; 
	 	}  
	 	return $(this.ClickRow).attr("choose_id");       
	 };
	
	 this.selectrow =function  (no) { 
		   if(hashead && no==0)
	    	{
	    	   return;
	    	}
		   if (no > (this.Main_TabDom.rows -1)){
				no = this.Main_TabDom.rows -1;
			}   
			if (this.Main_TabDom.rows[no]!=null && this.Main_TabDom.rows[no] != undefined)
			{ 
				if (this.ClickRow!=null && this.ClickRow != undefined &&  this.ClickRow !=this.Main_TabDom.rows[no])
				{ 
					$(this.ClickRow).removeClass('select');
				} 
				this.ClickRow =this.Main_TabDom.rows[no];
				$(this.ClickRow).addClass('select'); 
				if(window.datagrid_selectrow ){ 
	    		   window.datagrid_selectrow(this.ClickRow,this.ClickRow.rowIndex); 
	    		}
			}
	};
	
	this.Main_Tab.get(0).onclick=  function (){ 
	    	var the_obj = event.srcElement; 
	    	    var the_tr	= get_Element(the_obj,"tr");
	    		if(the_tr==null || the_tr.rowIndex==0) return;  
	    		Me.selectrow(the_tr.rowIndex);   
	    		if(window.datagrid_click ){ 
	    		   window.datagrid_click(the_tr,the_tr.rowIndex); 
	    		}
	    };  
	    
	    
	    this.Main_Tab.get(0).ondblclick= function (){ 
	    	var the_obj = event.srcElement;
	    	 var the_tr	= get_Element(the_obj,"tr");
	    		if(the_tr==null || the_tr.rowIndex==0) return; 
	    		Me.selectrow(the_tr.rowIndex);    
	    		if(window.datagrid_dblclick ){ 
	    		   window.datagrid_dblclick(the_tr,the_tr.rowIndex); 
	    		}
	    	 
	    }   ;
	    
	    this.Main_Tab.get(0).onkeydown= function () {  
		    if (event.keyCode ==13 ){
		        var the_obj = event.srcElement;
		        var the_tr	= get_Element(the_obj,"tr");
	    		if(the_tr==null || the_tr.rowIndex==0) return; 
	    		Me.selectrow(the_tr.rowIndex);   
				if(window.datagrid_dblclick ){ 
				   window.datagrid_dblclick(the_tr,the_tr.rowIndex); 
				} 
		      }  
		};   
}
   

function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];  
    if (e.name != 'checkall' && e.type =='checkbox' && !e.disabled)
       e.checked = form.checkall.checked;
    }
} 